<?php
class IssueLink extends Zend_Db_Table
{
	protected $_name = "issuelink";
	
	function getDuplicatedIssues($issueId)
	{
		$select = $this->_db->select()
							->from($this->_name,null)
							->join(array('issue'=>'issue'),'issue.id = issuelink.destination')
							->joinLeft(array('priority'=>'priority'),'
												issue.priority=priority.id',
														array('priorityName'=>'pname',
															  'priorityIcon'=>'icon_url',
															  'priorityDesc' => 'description'))
							->joinLeft(array('issuestatus'=>'issuestatus'),
											'issuestatus.id = issue.issuestatus',
													array('issueStatusName'=>'pname',
														  'issueStatusIcon'=>'icon_url',
														  'issueStatusDesc' => 'description'))
							->joinLeft(array('resolution'=>'resolution'),
											'issue.resolution=resolution.id',
														array('resolutionName'=>'pname',
														'resolutionDesc' => 'description'))
							->joinLeft(array('issuetype'=>'issuetype'),
											'issue.issuetype=issuetype.id',
													array('issueTypeName'=>'pname',
														  'issueTypeIcon'=>'icon_url',
														   'issueTypeDesc' => 'description'))
							->where('issuelink.source = ?', $issueId)
							->where('issuelink.linktype = "1"');
		$results = $this->getAdapter()->fetchAll($select);
		return $results;
	}
	
	function getDuplicateIssues($issueId)
	{
		$select = $this->_db->select()
							->from($this->_name,null)
							->join(array('issue'=>'issue'),'issue.id = issuelink.destination')
							->joinLeft(array('priority'=>'priority'),'
												issue.priority=priority.id',
														array('priorityName'=>'pname',
															  'priorityIcon'=>'icon_url',
															  'priorityDesc' => 'description'))
							->joinLeft(array('issuestatus'=>'issuestatus'),
											'issuestatus.id = issue.issuestatus',
													array('issueStatusName'=>'pname',
														  'issueStatusIcon'=>'icon_url',
														  'issueStatusDesc' => 'description'))
							->joinLeft(array('resolution'=>'resolution'),
											'issue.resolution=resolution.id',
														array('resolutionName'=>'pname',
														'resolutionDesc' => 'description'))
							->joinLeft(array('issuetype'=>'issuetype'),
											'issue.issuetype=issuetype.id',
													array('issueTypeName'=>'pname',
														  'issueTypeIcon'=>'icon_url',
														   'issueTypeDesc' => 'description'))
							->where('issuelink.source = ?', $issueId)
							->where('issuelink.linktype = "2"');
		$results = $this->getAdapter()->fetchAll($select);
		return $results;
	}
	
}